<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    //数组新增了map和reduce方法
    //1）、map    map()：接收一个函数，将原数组中的所有元素用这个函数处理后放入新数组返回
    let arr = ['1','20','-5','3'];
    console.log(arr);

    arr = arr.map(s => parseInt(s))
    console.log(arr)

    //2）、reduce
    const arr1 = [1,20,-5,3];
    //没有初始值:
    console.log(arr1.reduce((a,b)=>a+b));
    console.log(arr1.reduce((a,b)=>a*b));

    //指定初始值
    console.log(arr.reduce((a,b)=>a+b,1));
    console.log(arr.reduce((a,b)=>a*b,0));
</script>
<body>
    
</body>
</html>